	<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="/resource/UserPwoer.tld" prefix="p"%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<LINK rel="Bookmark" href="../images/favicon.ico">
<!-- 本框架基本脚本和样式 -->
<script type="text/javascript"
	src="${path }/resource/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript"
	src="${path }/resource/js/systools/MBase.js"></script>
<script type="text/javascript" 
	src="${path }/resource/plugin/ajaxfileupload.js"  ></script>
</head>
<body class="gray-bg">
	<nav class="huiNav">
		<%@include file="project-nav.jsp" %>${param.projName }
		<a class="btn btn-info  btn-sm pull-right"
			href="javascript:location.replace(location.href);" title="刷新"><i
			class="fa fa-refresh"></i></a>
	</nav>

	<div class="ibox-content">
	<%-- <jsp:include page="proj-manager-son.jsp"></jsp:include> --%>
	<!-- 搜索框部分start -->
	<div class="row">
		<div class="col-sm-9">
			<form class="form-inline" id="serchform">
			<input type="hidden" name="projId" id="projId" value="${param.projId}">
			<div class="form-group mr-20">
				<label for="exampleInputName2">功能模块</label>
				<select class="form-control select2" size="1" name="modelId"
						id="parentId">
						<option value="" selected="selected">请选择功能模块</option>
					</select>
			</div>
			<div class="form-group mr-20">
				<label for="exampleInputName2">标题</label>
				<input name="title" type="text" class="form-control" value=""  >
			</div>
		<div class="form-group mr-20">
				<label for="exampleInputName2">编号</label>
				<input name="caseNo" type="text" class="form-control" value=""  >
			</div>
		<div class="form-group mr-20">
				<label for="exampleInputName2">类型</label>
			<select class="form-control autoFull" name="caseType" dataType="*"
						data-url="${path}/admin/dataDictionary/showDataDictionary"
						data-filed="name" data-value="name" data-param="{type:'用例类型'}"
						>
						<option value="">--请选择用例类型--</option>
					</select>
			</div>
		<div class="form-group mr-20">
				<label for="exampleInputName2">优先级</label>
			<select class="form-control autoFull" name="grade" >
			<option value="">--请选择优先级--</option>
						<option value="1">1</option>
						<option value="2">2</option>
						<option value="3">3</option>
						<option value="4">4</option>
					</select>
			</div>
		<div class="form-group mr-20">
				<label for="exampleInputName2">状态</label>
			<select class="form-control autoFull" name="caseStatus" >
			<option value="">--请选择优状态--</option>
						<option value="通过">通过</option>
						<option value="N/A">N/A</option>
						<option value="失败">失败
						</option>
						<option value="阻塞">阻塞</option>
					</select>
			</div>
			<button  onclick="myGrid.serchData()" type="button" class="btn btn-info btn-sm"><i class="fa fa-search " ></i> 搜索</button>
			<button  type="reset" class="btn btn-info btn-sm"><i class="fa fa-refresh " ></i> 重置</button>
		</form>
		</div>
	</div>
	<!-- 搜索框部分en -->
		<div style="position: relative; top: 40px;z-index: 12;width:500px;">
			<button onclick="myGrid.delItems('caseId')" type="button" class="btn btn-danger btn-sm"><i class="fa fa-trash" ></i>批量删除</button>
			<button onclick="putIn()" type="button" class="btn btn-success btn-sm"><i class="fa fa-sign-in" ></i>  通用用例导入</button>
			<button onclick="openAdd()" type="button" class="btn btn-success btn-sm"><i class="fa fa-plus" ></i>  新增</button>
			<button onclick="excleputIn()" type="button" class="btn btn-success btn-sm"><i class="fa fa-sign-in" ></i>  EXCEL导入</button>
			<a    class="btn btn-success btn-sm"  href="${path }/admin/userCase/exportUserCaseExcel?projId=${param.projId}"  target="blank"><i class="fa fa-sign-in" ></i>  EXCEL导出</a>
		</div> 
		
		
		
		<div style="position: relative; top: 60px;z-index: 12;width:800px;" id="excleput" style="display: none;">
				<form class="form-horizontal" id="dataform"
					onsubmit="javascripr:return false;">
						<div class="form-group">
							<label class="col-sm-2 control-label">导入用例excel<span class="text-danger">*</span></label>
							<div class="col-sm-9">
								<input onclick="importData()"
									class="input-text upload-url radius form-control" type="text" id="showFileName"
									readonly style="width: 30%;display: inline;"> 
									<a onclick="importData()" class="btn btn-primary radius"> 
									<i class="fa fa-cloud-upload"></i> 浏览文件 </a> 
									<a class='btn btn-primary radius' download href="<c:out value='${path}/resource/excel/userCase.xlsx'></c:out>">下载用例编辑模板</a> 
								<button type="button"onclick="submitData()" class="btn btn-success radius">导入</button>&nbsp;&nbsp;&nbsp;&nbsp;
								<input type="file" name="file" accept=".xls,.xlsx" type="hidden" id="chanceUploadId" style="display:none">	
							</div>
						</div>
				</form>
		</div>
		
		<div class="row">
			<div class="col-md-12" >
			<table id="mgrid">
			<thead>
				<tr>
					<th data-checkbox="true"></th>
					<th data-field="caseNo" >编号</th>
					<th data-field="title" data-formatter="buidTitle" >标题</th>
					<th data-field="caseType" >用例类型</th>
					<th data-field="userStage" >适用阶段</th>
					<th data-field="userName" >创建人</th>
					<th data-field="createTime" data-formatter="MGrid.getTime" >创建时间</th>
					<th data-field="success" data-formatter="buidSuccess" >成功：失败</th>
					<th data-field="caseStatus" data-formatter="buidStatus" >状态</th>
					<th data-align="center"  data-width="195px" data-field="caseId" data-formatter="buidOperate">操作</th>
				</tr>
			</thead>
		</table>
			</div>
		</div> 
	</div>
	<script type="text/javascript">
	
	var myGrid;
		$(function(){
			var delUrl="";
				delUrl="${path}/admin/userCase/del";
			 myGrid=MGrid.initGrid({
			 	 url:"${path}/admin/userCase/showList",
				 delUrl:delUrl,
			 });
			
		});
		function buidTitle(value,row,index){
			return '<span  class="badge badge-info" >'+row.grade+'</span> '+value;
		}
		function buidSuccess(value,row,index){
			return "<b>" +row.success+' : '+row.fail+"</b>";
		}
		function buidStatus(value, row, index){
			var color ="";
			if(value=="通过"){color="success"}
			else if(value=="失败"){color="danger"}
			else if(value=="N/A"){color="default"}
			else if(value=="正常"){color="info"}
			else if(value=="阻塞"){color="warning"}
			return "<span class='label label-"+color+"'>"+value+"</span>";
		}
		function buidOperate(value, row, index){
			var html='';
			html+='<button class="btn btn-default btn-sm mr-5" onClick="exeCase('+value+')" title="执行"><i class="fa fa-play"></i></buttoun>';
			html+='<button class="btn btn-default btn-sm mr-5" onClick="openEdit('+value+')" title="编辑"><i class="fa fa-edit"></i></buttoun>';
			html+='<button class="btn btn-default btn-sm mr-5" onClick="myGrid.delItem('+value+')" title="删除"><i class="fa fa-lg fa-trash-o"></i></buttoun>';
			return html; 
		}
		//打开添加界面
		function openAdd() {
			layer.full(layer.open({
				type : 2,
				title : "新增用例",
				area : [ MUI.SIZE_L, '400px' ],
				content : [ '${path}/admin/userCase/editForm?projId=${param.projId}']
			})); 
		}
		//打开导入通用用例的界面
		function putIn() {
			layer.full(layer.open({
				type : 2,
				title : "导入通用用例",
				area : [ MUI.SIZE_L, '400px' ],
				content : [ '${path}/admin/userCase/putInForm?projId=${param.projId}']
			})); 
		}
		//打开编辑界面
		function openEdit(id) {
			layer.full(layer.open({
				type : 2,
				title : "编辑用例",
				area : [ MUI.SIZE_L, '400px' ],
				content : [ '${path}/admin/userCase/editForm?id=' +id+'&projId=${param.projId}']
			}));
		} 
		//打开编辑界面
		function exeCase(id) {
			layer.open({
				type : 2,
				title : false,
				area : [ MUI.SIZE_L, '500px' ],
				content : [ '${path}/admin/userCase/exeCase?id=' +id]
			});
		} 
		$(".select2").select2({
			'width' : '100%'
		});
		MTools.autoFullSelect();
		initModelList();
		//初始化项目模块
		function initModelList(projId) {
			$.AjaxProxy({
				a : false,
				c : false
			}).invoke(
					"${path}/admin/interfaceCate/all?projId="
							+ $(":input[name=projId]").val(), function(loj) {
						$("#parentId").createSelectTree(loj.attr("result").rows, {
							append : false,
							defaultValue : "${obj.modelId}"
						});
					});
		}
		
		//excel上传
		//绑定文件的点击事件
		function importData(){
			var file=$("#chanceUploadId").click();
		}
		//选中文件，文件名字显示在文本框中
		$("#chanceUploadId").change(function(){
			$("#showFileName").val('');
			$("#showFileName").val($(this).val());
		});
		
		//提交文件
		function submitData(){
			if($("#showFileName").val()=='' || $("#showFileName").val().length<1){
				layer.msg("请选择上传文件！",{icon:2});
				return ;
			}
			var fileName = $("#showFileName").val();
			fileName = fileName.substring(fileName.lastIndexOf("\\")+1,fileName.lastIndexOf("."));		
			 var index = layer.load(1, {
	        	  shade: [0.6,'#fff'] //0.1透明度的白色背景
	        	});		 
			var projid = $(':input[name=projId]').val();
			$.ajaxFileUpload({			
				url : "${path}/admin/userCase/importData?projId="+projid+"" ,
				type : "POST",
				secureuri : false,// 一般设置为false
				fileElementId : "chanceUploadId",// 文件上传空间的id属性 <input type="file" id="uploadId" />
				dataType : "json",
				success : function(data) {			
					if(data.status=='成功'){
						alert("导入成功");
						location.reload() 
					}else{
						alert("导入失败");
					}
					layer.close(index);
				}
			}); 
		}	
	</script>
	<script>
		$("#excleput").hide();
		var log = 1;
		function excleputIn(){
			if(log==1){
				$("#excleput").show();			
				log=0;
			}else{
				$("#excleput").hide();
				log=1;
			}
		}
	</script>
</body>
</html>
